﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<List<ForumsListEntity>>" %>
<%

    
    //int _parentId=Request.QueryString[]

    var forumId = Convert.ToInt32(ViewData["ForumId"]);
    var _Parents = forumId > 0 ? Model.Where(x => x.ForumId == forumId) : Model.Where(x => x.ParentId == forumId);


    if (_Parents.Count() > 0)
    {

        foreach (var parent in _Parents)
        {

            var _subForums = Model.Where(x => x.ParentId == parent.ForumId);

            if (ForumContext.ForumAllowAccess(parent.AllowRoles) && (parent.ParentId == 0 || _subForums.Count() > 0))
            {



%>
<div class="fr-widget white-space">
    <div class="header">
        <div class="collapse collapse-close {collapseId:'#collapse_panel_<%=parent.ForumId%>'}">
        </div>
        <div class="icon">
        </div>
        <a class="fr-subject" href="<%=ForumContext.ForumLink(parent.ForumId, parent.ForumName, null)%>"
            title="<%=Html.Encode(parent.ForumName)%>"><%=Html.Encode(parent.ForumName)%></a>
    </div>
    <div id="collapse_panel_<%=parent.ForumId%>">
        <table cellpadding="0" cellspacing="1" width="100%">
            <tr>
                <td class="table-header width5">
                    &nbsp;
                </td>
                <td class="table-header">
                    <%=ForumContext.GetText("FORUM","FORUM") %>
                </td>
                <td class="table-header width40">
                    <%=ForumContext.GetText("FORUM","LAST_POST") %>
                </td>
                <td class="table-header width8">
                    <%=ForumContext.GetText("FORUM", "TOTALTOPICS")%>
                </td>
                <td class="table-header width8">
                    <%=ForumContext.GetText("FORUM", "TOTALPOSTS")%>
                </td>
            </tr>
            <%


                foreach (var subForum in _subForums)
                {
                
            %>
            <tr>
                <td class="table-cell table-cell-height">
                   <%=ForumContext.ForumIcon(subForum) %>
                </td>
                <td class="table-cell-alter">
                   <%-- <a class="fr-subject" title="<%=Html.Encode(subForum.ForumName)%>" href="<%=ForumContext.ForumLink(subForum.ForumId, subForum.ForumName, null)%>">
                        <%=Html.Encode(subForum.ForumName)%></a>--%>
                        <%=ForumContext.ForumLink(subForum) %>
                    <% =  !string.IsNullOrEmpty(subForum.Description) ? string.Format("<br /><span class=\"fr-description\">{0}</span>", subForum.Description) : string.Empty%>
                    <%
                        var _subForumLevel3 = Model.Where(x => x.ParentId == subForum.ForumId);

                        if (_subForumLevel3.Count() > 0)
                        {


                    %>
                   
                        <%=ForumContext.GetGlobalText("SUB_FORUM")%>
                    <ul class="fr-subforum">
                        <%foreach (var _sub3 in _subForumLevel3)
                          {

                        %>
                        <li><%=ForumContext.ForumLink(_sub3)%><span><%= _sub3.TotalTopics>0?string.Format(" ({0}/{1})",_sub3.TotalTopics,_sub3.TotalReplies):string.Empty %></span></li>
                        <%
                            }%>
                    </ul>
                    <%
}%>
                </td>
                <td class="table-cell">
                    <% if (subForum.LastPostId > 0)
{

                string _findPost = ForumContext.FindPost(subForum.LastPostId, subForum.LastPostTitle);

                    %>
                    <a class="fr-subject" title="<%=Html.Encode(subForum.LastPostTitle)%>" href="<%=_findPost  %>">
                        <%=Html.Encode(subForum.LastPostTitle)%></a><br />
                    <a title="<%=ForumContext.GetText("Topics", "VIEW_LAST_POST") %>" href="<%=_findPost %>"
                        class="last-post"><span class="post-date">
                            <%=ForumContext.PrettyDate(subForum.LastPostDate)%></span></a><br />
                    <%=string.Format(ForumContext.GetGlobalText("POSTER"), subForum.LastUserPost, ForumContext.GetAbsoluteUrl(ForumUrls.USER_INFO, subForum.LastUserPost))%>
                    <%
                        }
                       else
                       {

                           Response.Write(ForumContext.GetText("Forum", "LAST_POST_EMPTY"));
                       }%>
                </td>
                <td class="table-cell-alter center">
                    <%=subForum.TotalTopics%>
                </td>
                <td class="table-cell center">
                    <%=subForum.TotalReplies%>
                </td>
            </tr>
            <%
                }%>
        </table>
    </div>
</div>
<%
}
        }
    }%>
